package com.sita.bike.task;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by manhongyun on 15/11/12.
 */
public class ImageAdapter extends BaseAdapter {
    private Context context;
    private List<ImageBean> list = new ArrayList<ImageBean>();

    public ImageAdapter(Context context, List<ImageBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        LinearLayout layout = new LinearLayout(context);
        ImageView imageView = new ImageView(context);
        layout.addView(imageView);
        ImageBean bean = list.get(position);
        if (bean.getBitmap() != null) {
            imageView.setImageBitmap(bean.getBitmap());
        }
        if (bean.isNeedBar()) {
            ProgressBar bar = new ProgressBar(context);
            layout.addView(bar);
        }
        return layout;
    }

}
